var fs = require('fs');
var crypto = require('crypto');
var path = 'app.js';
const md5 = function(path){
    return new Promise((resolve, reject) => {
        var md5sum = crypto.createHash('md5');
        var stream = fs.createReadStream(path);
        stream.on('data', function (chunk) {
            md5sum.update(chunk);
        });
        stream.on('end', function () {
            str = md5sum.digest('hex');
            
            resolve(str);
        });
        stream.on('error', function(err) {
            reject(err);
        });
    })
};

var start = new Date().getTime();
// path = 'ff.js';
md5(path).then(function(str){
    console.log('文件:' + path + ', MD5签名为: 【' + str + '】.耗时:' + (new Date().getTime() - start) / 1000.00 + "秒");
}).catch(function(err){
    console.log(err);
})